#import "CTPWikiProxyFetcher.h"
#import "NSString+URLEncoding.h"
#import "CTPFlickrData.h"
#import "CTPFlickrFetcher.h"
#import "CTPFlickrParser.h"

@implementation CTPFlickrFetcher

- (void)requestSucceeded {
	NSString *responseString = [[NSString alloc] initWithData:recievedData encoding:NSUTF8StringEncoding];
	CTPFlickrParser *parser = [CTPFlickrParser alloc];
	//NSLog(@"result: %@", responseString);
	NSMutableArray *array = [parser parse:responseString];
	[delegate flickrFetcherSucceeded: self data:array];
	[delegate flickrFetcherEnd:self];
}

-(void)requestFailed:(NSError*)error {
	[delegate flickrFetcherFailed:self];
	[delegate flickrFetcherEnd:self];
}

-(NSString*) URLForFlickr:(NSString*) tags{
	NSString* url = [NSString stringWithFormat:
					 @"http://114.34.48.246/CtpSvr/CtpFlickrProxy.ashx?key=%@", 
					 tags];
	return url;
}

-(void)getDataFromFlickr:(NSString*) tags{
	NSString* url = [self URLForFlickr:tags];
	NSLog(@"%@", url);
	[super requestGET:url];
	[delegate flickrFetcherBegin:self];
}


@synthesize delegate;

@end